<?php
/**
 * 
 * 功能描述
 * 不涉及任何展示功能
 * @author Administrator
 *
 */
class VoteModel extends Db {
	
	//投票队列  谁投票
	private $_vote_list = 'w_vote_list';
	//参赛队员
	private $_vote_user = 'w_vote_user';
	
	public function getAllTickets() {
		return $this->getAll ( $this->_vote_user );
	}
	
	public function addList($params) {
		$this->add ( $this->_vote_list, $params );
		return $this->lastInsertId ();
	}
	
	public function saveTicketsById($id) {
		$sql = "UPDATE $this->_vote_user SET tickets=tickets+1 WHERE id=$id";
		return $this->exec ( $sql );
	
	}
	

	
	
	public function countTicketsByTime($uid, $startTime) {
		$sql = "SELECT count(id) num FROM $this->_vote_list WHERE add_time>$startTime AND uid=$uid";
		return $this->fetch ( $sql );
	}
	
	public function addUser($params) {
		$this->add ( $this->_vote_user, $params );
	}
	
	public function getTicketsById($id) {
		return $this->getOne ( $this->_vote_user, array ('id' => $id ) );
	}
	
	/**
	 * 返回VoteModel
	 * @return VoteModel
	 */
	public static function instance() {
		return parent::_instance ( __CLASS__ );
	}
}